package client;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.ArrayList;
import java.util.Scanner;

public class Fclient extends Client {
	private Service service;
	public Fclient(Service s) {
		super(s);
	}
	
	public String checkFlight(String text) {
		String input = null;
		try {
			Service thisServer = getServer();
			Socket socket = new Socket(thisServer.getIpAddress(), thisServer.getPort());
			PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
			System.out.println("\nMain Client: Fclient is sending the Message :::"+text+"\n");
			out.println(text);
			out.flush();
			
		
			
			
			BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
			
		    input = in.readLine();
			System.out.println("Fclient's Msg to ClientPanel  "+input);
			out.close();
			in.close();
			
			
			
		} catch (IOException e) {
			e.printStackTrace();
		}
		return input;
	}


	public void run() {
			System.out.println("Service Discovered: " + service);
		
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			String response;
            try {
	            response = br.readLine();
	            String arg = response;
	            
	            
	            
	            checkFlight(arg);
	            
            } catch (IOException e) {
	            e.printStackTrace();
            }
	}

}
